package com.tarena.redis.demo.service;

import com.tarena.redis.demo.dao.StockDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StockService {
    //模拟商品下单的时候 减库存操作 买2个风扇 但是库存只有1个 减库存就失败了 如果库存0
    @Autowired
    private StockDao stockDao;
    public boolean reduceStock(String id){
        //先判断库存是否大于0 模拟减库存1个
        Integer stock = stockDao.getStock(id);
        if(stock>0){
            //有库存就减库存
            stockDao.reduceStock(id);
            return true;
        }
        return false;
    }
}
